﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySkiPatrolEntity;

namespace MySkiPatrolVAL
{
    public static class PatrolVLO
    {
        public static Patrol NewPatrol(Patrol data)
        {
            if (data == null)
            {
                //you must have a PATROL to validate!
                data = new Patrol();
                data.DataTransaction = new DataTransaction();
                data.DataTransaction.TransactionErrors = new List<Error>();
                data.DataTransaction.TransactionErrors.Add(new Error("VAL10000","The patrol object is null"));
                data.DataTransaction.Success = false;
            }
            else
            {
                if (data.DataTransaction == null) data.DataTransaction = new DataTransaction();
                data.DataTransaction.Success = true;

                //do we have objects?
                if (string.IsNullOrEmpty(data.ID)) data.DataTransaction.TransactionErrors.Add(new Error("VAL10001", "The patrol is missing an ID"));
                if (string.IsNullOrEmpty(data.dbPrefix)) data.DataTransaction.TransactionErrors.Add(new Error("VAL10002", "The patrol is missing a dbPrefix"));
                if (string.IsNullOrEmpty(data.Name)) data.DataTransaction.TransactionErrors.Add(new Error("VAL10003", "The patrol is missing a Name"));
                if (string.IsNullOrEmpty(data.SubDomain)) data.DataTransaction.TransactionErrors.Add(new Error("VAL10004", "The patrol is missing a SubDomain"));
                if (string.IsNullOrEmpty(data.Title)) data.DataTransaction.TransactionErrors.Add(new Error("VAL10005", "The patrol is missing a Title"));

                //check for proper size
                if (data.dbPrefix.Length > 5) data.DataTransaction.TransactionErrors.Add(new Error("VAL10006", "The patrol's dbPrefix exceeds the maximum size of 5 characters"));
                if (data.SubDomain.Length > 25) data.DataTransaction.TransactionErrors.Add(new Error("VAL10007", "The patrol's SubDomain exceeds the maximum size of 25 characters"));
                if (data.Name.Length > 150) data.DataTransaction.TransactionErrors.Add(new Error("VAL10008", "The patrol's Name exceeds the maximum size of 150 characters"));
                if (data.Title.Length > 150) data.DataTransaction.TransactionErrors.Add(new Error("VAL10009", "The patrol's Title exceeds the maximum size of 150 characters"));

                //all done...did we have validation errors?
                if (data.DataTransaction.TransactionErrors.Count > 0) data.DataTransaction.Success = false;
            }
            return data;
        }

        
    }
}
